package com.hansintelligent.rrrmvpframework.view.login.presenter;


import com.hansintelligent.rrrmvpframework.base.BaseResponse;
import com.hansintelligent.rrrmvpframework.base.mvp.BasePresenter;
import com.hansintelligent.rrrmvpframework.bean.UserInfo;
import com.hansintelligent.rrrmvpframework.view.login.contract.LoginContract;
import com.hansintelligent.rrrmvpframework.view.login.model.LoginModel;
import com.hansintelligent.rrrmvpframework.network.APICallBack;
import com.hansintelligent.rrrmvpframework.network.RxTransformer;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * LoginPresenter
 * Created by wangfu on 2017/10/20.
 */

public class LoginPresenter extends BasePresenter<LoginContract.IViewContract>
        implements LoginContract.IPresenterContract {

    private LoginModel mLoginModel;


    public LoginPresenter() {
        mLoginModel = new LoginModel();
    }


    /**
     * login
     */
    @Override
    public void login() {

        mLoginModel.login("18158653013", "y0000000")
                .compose(RxTransformer.<BaseResponse<UserInfo>>transformer(getMvpView()))
                .subscribe(new APICallBack<BaseResponse<UserInfo>>() {

                    @Override
                    public void onStart(@NonNull Disposable d) {
                   getMvpView().showLoading();
                    }

                    @Override
                    public void onSuccess(BaseResponse<UserInfo> modelBean) {
                       getMvpView().loginSuccess(modelBean.getContent());
                    }

                    @Override
                    public void onFailure(String errorMsg) {

                    }

                    @Override
                    public void onFinished() {
                        getMvpView().hideLoading();
                    }
                });

    }

}
